﻿using ServiceStack.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Publicuse.Interface
{
    /// <summary>
    /// Redis操作基类
    /// </summary>s
    public interface IRedisService
    {
        /// <summary>
        /// 获取Hash所有的数据转换为字典集合
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        Dictionary<string, string> GetHashToDictionaryByKey(int conIndex, int dbIndex, out string msg, string key);

        /// <summary>
        /// 获取Hash所有数据转换为实体对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        T GetHashToObjectByKey<T>(int conIndex, int dbIndex, out string msg, string key) where T : new();

        /// <summary>
        /// 获取Hash对应多个Key对应的值
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="names"></param>
        /// <returns></returns>
        List<string> GetHashMoreByKeys(int conIndex, int dbIndex, out string msg, string key, string[] names);

        /// <summary>
        ///获取Hash对应Key对应值
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        string GetHashValuByKey(int conIndex, int dbIndex, out string msg, string key, string name);

        /// <summary>
        /// 获取Hash包含特定字符的集合
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        Dictionary<string, string> GetHashValuLikeKey(int conIndex, int dbIndex, out string msg, string key, string value);

        /// <summary>
        ///  获取SortedSet包含特定字符的集合
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        Dictionary<string, double> GetSortSetLikeKey(int conIndex, int dbIndex, out string msg, string key, string value);

        /// <summary>
        ///  获取Set包含特定字符的集合
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        List<string> GetSetLikeKey(int conIndex, int dbIndex, out string msg, string key, string value);

        /// <summary>
        /// 获取Hash某个Key的数量
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        long GetHashLengthByKey(int conIndex, int dbIndex, out string msg, string key);

        /// <summary>
        /// 插入对象到Hash
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="trans"></param>
        /// <param name="key"></param>
        /// <param name="suit"></param>
        void AddDbjectToHash<T>(int conIndex, int dbIndex, out string msg, string key, T suit) where T : new();

        /// <summary>
        /// 插入单个值到Hash
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        void AddHashValueByKey(int conIndex, int dbIndex, out string msg, string key, string name, string value);

        /// <summary>
        /// 判断Hash某个Key是否存在
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="name"></param>
        bool HashExists(int conIndex, int dbIndex, out string msg, string key, string name);

        /// <summary>
        /// 判断Set某个Key是否存在
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        bool SetExists(int conIndex, int dbIndex, out string msg, string key, string name);

        /// <summary>
        /// 插入多个值到Hash
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="keyValues"></param>
        void AddHashValuesByKey(int conIndex, int dbIndex, out string msg, string key, Dictionary<string, string> keyValues);

        /// <summary>
        ///  如果hashid集合中存在key/value则不添加返回false，
        ///  如果不存在在添加key/value,返回true
        /// </summary>
        /// <param name="client"></param>
        /// <param name="hashid"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        bool AddHashValueByKeyNotExists(int conIndex, int dbIndex, out string msg, string hashid, string key, string value);

        /// <summary>
        /// 修改Hash对应Key的Value加1
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        void AddHashValuesByKeyAdd(int conIndex, int dbIndex, out string msg, string key, string name, int value = 1);

        /// <summary>
        /// 修改Hash对应Key的Value加1
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        void AddHashValuesByKeyAdd(int conIndex, int dbIndex, out string msg, string key, string name, long value = 1);

        /// <summary>
        /// 移除Hash对应Key对应值
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="name"></param>
        void DeleteHashValueByKey(int conIndex, int dbIndex, out string msg, string key, string name);

        /// <summary>
        /// 移除有序集合对应Key对应值
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="name"></param>
        void DeleteSortedSetValueByKey(int conIndex, int dbIndex, out string msg, string key, string name);

        /// <summary>
        /// 插入数据到Sorted
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        void AddSet(int conIndex, int dbIndex, out string msg, string key, string value);

        /// <summary>
        /// 插入多条数据到Sorted
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="values"></param>
        void AddSets(int conIndex, int dbIndex, out string msg, string key, List<string> values);

        /// <summary>
        /// 插入数据到SortedSet
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="time"></param>
        void AddSortedSet(int conIndex, int dbIndex, out string msg, string key, string value, long time);

        /// <summary>
        ///  插入数据到SortedSet
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="score"></param>
        void AddSortedSet(int conIndex, int dbIndex, out string msg, string key, string value, double score);

        /// <summary>
        ///  插入数据到SortedSet
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        void AddSortedSet(int conIndex, int dbIndex, out string msg, string key, string value);

        /// <summary>
        /// 插入多条数据到SortedSet
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="values"></param>
        /// <param name="time"></param>
        void AddSortedSets(int conIndex, int dbIndex, out string msg, string key, List<string> values, double time);

        /// <summary>
        /// 判断某个Key信息是否存在
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        bool KeyExists(int conIndex, int dbIndex, out string msg, string key);

        /// <summary>
        /// 设置过期时间
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="timeSpan"></param>
        void SetKeyExpire(int conIndex, int dbIndex, out string msg, string key, TimeSpan timeSpan);

        /// <summary>
        /// 插入数据到队列
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="jsonData"></param>
        void AddDataToQueue(int conIndex, int dbIndex, out string msg, string key, string jsonData);

        /// <summary>
        ///从队列获取数据
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        string GetDataFromQueue(int conIndex, int dbIndex, out string msg, string key);

        /// <summary>
        /// 获取队列数据总数
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        long GetDataFromQueueLength(int conIndex, int dbIndex, out string msg, string key);

        /// <summary>
        /// 获取队列一条数据
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        string GetDataFromQueueOne(int conIndex, int dbIndex, out string msg, string key);

        /// <summary>
        /// 获取队列里面所有的数据
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        List<string> GetDataFromQueueList(int conIndex, int dbIndex, out string msg, string key);

        /// <summary>
        /// 获取SortedSet所有信息
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        List<string> GetAllSortSetList(int conIndex, int dbIndex, out string msg, string key);

        /// <summary>
        /// 获取SortedSet指定条数信息，倒叙排序
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="sortType"></param>
        /// <returns></returns>
        List<string> GetAllSortSetList(int conIndex, int dbIndex, out string msg, string key, int start, int end, int sortType);

        /// <summary>
        /// 移除某个Key数据
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        void DeleteDataByKey(int conIndex, int dbIndex, out string msg, string key);

        /// <summary>
        /// 删除多个Key数据
        /// </summary>
        /// <param name="client"></param>
        /// <param name="keys"></param>
        void DeleteDatasByKey(int conIndex, int dbIndex, out string msg, string[] keys);

        /// <summary>
        /// 移除Set某个Key数据
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        void DeleteSetByKey(int conIndex, int dbIndex, out string msg, string key, string value);

        /// <summary>
        /// 获取所有的Set数据
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        List<string> GetSetAll(int conIndex, int dbIndex, out string msg, string key);

        /// <summary>
        /// 插入单个数据到String
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        void AddStringData(int conIndex, int dbIndex, out string msg, string key, string value);


        /// <summary>
        /// 插入多个数据到String
        /// </summary>
        /// <param name="client"></param>
        /// <param name="list"></param>
        void AddStringDatas(int conIndex, int dbIndex, out string msg, Dictionary<string, string> list);

        /// <summary>
        /// 获取Stirng的值
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        string GetDataFromString(int conIndex, int dbIndex, out string msg, string key);

        /// <summary>
        /// 提交事务捕获异常
        /// </summary>
        /// <param name="conIndex"></param>
        /// <param name="dbIndex"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        bool CommitTransac(int conIndex, int dbIndex, out string msg);

        /// <summary>
        /// 更换Redis索引库,默认是0号索引库
        /// </summary>
        /// <param name="client"></param>
        /// <param name="newDb"></param>
        /// <returns></returns>
        IRedisClient ChangeDB(int conIndex, int dbIndex, out string msg, int newDb);

        /// <summary>
        /// 发布订阅
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="message"></param>
        /// <param name="msg"></param>
        void Publishsubscribe(int conIndex, int dbIndex, out string msg, string key, string message);

        /// <summary>
        /// 取消要发布的订阅
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="msg"></param>
        void Cancelsubscription(int conIndex, int dbIndex, out string msg, string key);

        /// <summary>
        /// 订阅
        /// </summary>
        /// <param name="client"></param>
        /// <param name="key"></param>
        /// <param name="actionOnMessage"></param>
        /// <param name="msg"></param>
        void Subscribe(int conIndex, int dbIndex, out string msg, string key, Action<string, string, IRedisSubscription> actionOnMessage);
    }
}
